package com.lgt.fishmall.member.service.impl;

import com.lgt.common.to.SaveAddressTo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lgt.common.utils.PageUtils;
import com.lgt.common.utils.Query;

import com.lgt.fishmall.member.dao.MemberReceiveAddressDao;
import com.lgt.fishmall.member.entity.MemberReceiveAddressEntity;
import com.lgt.fishmall.member.service.MemberReceiveAddressService;


@Service("memberReceiveAddressService")
public class MemberReceiveAddressServiceImpl extends ServiceImpl<MemberReceiveAddressDao, MemberReceiveAddressEntity> implements MemberReceiveAddressService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberReceiveAddressEntity> page = this.page(
                new Query<MemberReceiveAddressEntity>().getPage(params),
                new QueryWrapper<MemberReceiveAddressEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<MemberReceiveAddressEntity> getAddress(Long memberId) {

        List<MemberReceiveAddressEntity> addressList = this.baseMapper.selectList
                (new QueryWrapper<MemberReceiveAddressEntity>().eq("member_id", memberId));

        return addressList;
    }

    @Override
    public void saveAddress(SaveAddressTo saveAddressTo) {
        MemberReceiveAddressEntity newAddress = new MemberReceiveAddressEntity();
        newAddress.setMemberId(saveAddressTo.getMemberId());
        newAddress.setName(saveAddressTo.getName());
        newAddress.setProvince(saveAddressTo.getProvince());
        newAddress.setCity(saveAddressTo.getCity());
        newAddress.setRegion(saveAddressTo.getRegion());
        newAddress.setPhone(saveAddressTo.getPhone());
        this.baseMapper.insert(newAddress);

    }

}